from rest_framework import serializers

from .models import GoodsCategory, Goods, GoodsImage


class GoodsCategoryThirdLayerSerializer(serializers.ModelSerializer):
    class Meta:
        model = GoodsCategory
        fields = '__all__'


class GoodsCategorySecondLayerSerializer(serializers.ModelSerializer):
    sub_cat = GoodsCategoryThirdLayerSerializer(many=True)

    class Meta:
        model = GoodsCategory
        fields = "__all__"


class GoodsCategorySerializer(serializers.ModelSerializer):
    sub_cat = GoodsCategorySecondLayerSerializer(many=True)

    class Meta:
        model = GoodsCategory
        fields = "__all__"


class GoodsImageSerializer(serializers.ModelSerializer):
    class Meta:
        model = GoodsImage
        fields = ('image',)


class GoodsSerializer(serializers.ModelSerializer):
    image = GoodsImageSerializer(many=True)
    category = GoodsCategorySerializer(many=True)

    class Meta:
        model = Goods
        fields = '__all__'
